﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class adm_vlg_dieuKhoanSuDung : System.Web.UI.Page
{
    VLGDataContext _db8 = new VLGDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {

        if (IsPostBack) return;
        int type = Convert.ToInt32(Request.QueryString["type"]);
        var article = (from a in _db8.Articles
                       where a.type == type
                       select a).ToList();
        if (article != null && article.Count > 0)
        {
            txtContent.Text = article[0].content;
        }
       
    }
    
    protected void butt_save_Click(object sender, EventArgs e)
    {
     
        int type = Convert.ToInt32(Request.QueryString["type"]);

        var article = (from a in _db8.Articles
                       where a.type == type
                       select a).ToList();
        if (article != null && article.Count > 0)
        {
            article[0].content = txtContent.Text ;
            article[0].timeUpdate = DateTime.Now;
                
        }
        else
        {
            var ar = new Article();
            ar.content = txtContent.Text;
            ar.type = type;
            ar.timeUpdate = DateTime.Now;
            _db8.Articles.InsertOnSubmit(ar);

        }
        _db8.SubmitChanges();
        Message = "Cập nhật dữ liệu thành công";
       // Response.Redirect("article.aspx?type="+type);
    }

    public string Message { get; set; }
}